package com.wx.controller;

import com.wx.common.WrapMapper;
import com.wx.common.Wrapper;
import com.wx.domain.vo.AddressDataVo;
import com.wx.domain.vo.AddressTreeVo;
import com.wx.entity.SysAddress;
import com.wx.service.SysAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Title:      SysAddressController. </p>
 * <p>Description 省市区地址服务 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         <a href="xinglinglove1029@163.com"/>杨文生</a>
 * @since      2020/9/15 13:40
 */
@RestController
@RequestMapping(value = "/address", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "省市区地址管理", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class SysAddressController {

    @Resource
    private SysAddressService sysAddressService;

    /**
     * <p>Title:	  getChildrenByParentCode. </p>
     * <p>Description 根据父编码查询子节点信息</p>
     *
     * @param parentCode String
     * @return the wrapper
     * @Author <a href="xinglinglove1029@163.com"/>杨文生</a>
     * @CreateDate 2017 /8/17 19:04
     */
    @GetMapping("getChildrenByParentCode/{parentCode}")
    @ApiOperation(notes = "根据父编码查询子节点信息", httpMethod = "GET", value = "根据父编码查询子节点信息")
    public Wrapper<List<SysAddress>> getChildrenByParentCode(@PathVariable String parentCode) {
        List<SysAddress> sysAddressList = sysAddressService.getChildrenByParentCode(parentCode);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, sysAddressList);
    }


    @PostMapping(value = "/getTwoLevelTreeList")
    @ApiOperation(httpMethod = "POST", value = "查询所有省市两级地址树")
    public Wrapper<List<AddressTreeVo>> getTwoLevelTreeList() {
        List<AddressTreeVo> dicTreeVos = sysAddressService.treeList();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, dicTreeVos);
    }


    @PostMapping(value = "/treeList")
    @ApiOperation(httpMethod = "POST", value = "查询所有地址树")
    public Wrapper<List<AddressTreeVo>> treeList() {
        List<AddressTreeVo> dicTreeVos = sysAddressService.getAddressTree();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, dicTreeVos);
    }


    @PostMapping(value = "/getAddressInfo")
    @ApiOperation(httpMethod = "POST", value = "查询地址信息")
    public Wrapper<AddressDataVo> getAddressInfo() {
        AddressDataVo addressDataVo = sysAddressService.getAddressInfo();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, addressDataVo);
    }



}
